import { tableList } from '@/api/table'
import { DICT } from '@/api/config'
import { decorator } from './decorator'
import uploadFiles from '@/common/components/upload/uploadFiles'
export const formFields = (vm) => {
  return {
    'formSetting': {
      name: 'test',
      selfUpdate: true
    },
    'item': [
      {
        label: '姓名render',
        change: v => {
        },
        decorator: decorator.taskName,
        render (h, rules, change) {
          return <a-input v-decorator={rules} onChange={change} placeholder="真实姓名" />
        }
      },
      {
        label: '姓名a-Input',
        type: 'input',
        placeholder: '真实姓名',
        disabled: false,
        change: v => {
        },
        decorator: decorator.taskName1
      },
      {
        label: '下拉框接口',
        type: 'select',
        placeholder: '真实姓名2',
        option: () => new Promise((resolve, reject) => {
          tableList().then(res => {
            resolve(res.list)
          })
        }),
        lebalValue: { name: 'pname', value: 'id' },
        change: (value, event, formVm) => {
          console.log(value)
          console.log(event)
          console.log(vm)
          vm.decorator.item[1].label = '123123123123'
          formVm.test.setFieldsValue({ taskName1: value })
        },
        decorator: decorator.taskName2
      },
      {
        label: '下拉框静态数据',
        type: 'select',
        placeholder: '真实姓名3',
        option: [{ pname: 'test', id: '1' }, { pname: 'test1', id: '2' }, { pname: 'test3', id: '3' }],
        lebalValue: { name: 'pname', value: 'id' },
        decorator: decorator.taskName3
      },
      {
        label: '下拉框VUEX字典项数据',
        type: 'select',
        placeholder: '真实姓名3',
        option: () => new Promise((resolve, reject) => {
          DICT().then(res => {
            resolve(res.data)
          })
        }),
        decorator: decorator.taskName4
      },
      {
        label: '姓名4',
        type: 'date-picker',
        placeholder: '真实姓名4',
        valueFormat: 'YYYY-MM-DD',
        decorator: decorator.taskName5
      },
      {
        label: '姓名5',
        type: 'range-picker',
        placeholder: ['时间1', '时间2'],
        valueFormat: 'YYYY-MM-DD',
        decorator: decorator.taskName6
      },
      {
        label: '姓名6',
        type: 'range-picker',
        decorator: decorator.taskName7,
        myComponents: uploadFiles,
        render (h, rules) {
          return <uploadFiles v-decorator={rules} />
        }
      }
    ]
  }
}
